#include <pcap.h>
#include<stdio.h>

pcap_dumper_t *pdt;

int a=0;

void packet_handler(u_char *user, const struct pcap_pkthdr *pkt_header, const u_char *pkt_data)
{
	printf("1\n");

	if(a<32)
	{
		printf("I have got a packet\n");
		pcap_dump(user, pkt_header, pkt_data);
		a++;
		return;
	}
}

void main()
{

	printf("begin pcap_loop.");

	pcap_t *pcap_handle = pcap_init(1,"packet","eth0");
	pdt=pcap_dump_open(pcap_handle,"packet");

	if (pcap_handle == NULL) {
		printf("pcap_handle is NULL.");
		/* TODO:kill task */
		return;
	}

	//pcap_loop(pcap_handle, -1, &pcap_task_packet_process, NULL);
	pcap_loop(pcap_handle,0,packet_handler,(u_char*)pdt);
	/* NOT REACHED HERE */
	return;
}
